package com.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.example.item.Item;
import com.opensymphony.xwork2.ActionSupport;


public class ItemAction extends ActionSupport {

	private Item item;

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	@Action(value = "add", results = { @Result(name = "success", location = "/WEB-INF/content/item.jsp") })
	public String add() {
		item = new Item(0, "Computer", 6000.0);
		return SUCCESS;
	}

	@Action(value = "edit", results = { @Result(name = "success", location = "item.jsp") })
	public String edit() {
		item = new Item(100, "Computer", 6000.0);
		return SUCCESS;
	}

	@Action(value = "save", results = { @Result(name = "success", type = "httpheader", params = {
			"status", "500", "errorMessage", "Internal Error" }) })
	public String save() {
		System.out.println("item is " + item);
		return SUCCESS;
	}
}
